home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / amiga.free / sorgenti vari / wolfedit2 2.0.4 source.sit / WolfEdit2 2.0.4 Source / UEditEnemies.p < prev    next >
Text File  |  1996-04-03  |  6KB  |  240 lines

  1. unit UEditEnemies;
  2.  
  3. interface
  4.     uses
  5.         UWolfDoc;
  6.  
  7.     procedure IUEditEnemies;
  8.     procedure EditEnemies (mapList: TMapListDoc);
  9.  
  10. implementation
  11.     uses
  12.         UEditArt;
  13.  
  14.     const
  15.  
  16.         enemyEditDlogID = 138;
  17.         paletteItem = 2;
  18.         imageItem = 3;
  19.         frameMenuItem = 5;
  20.         prevFrameItem = 7;
  21.         nextFrameItem = 8;
  22.  
  23.         animRsrcID = 128;
  24.         frameMenuID = 143;
  25.  
  26.     type
  27.  
  28.         AnimHandle = ^AnimPtr;
  29.         AnimPtr = ^AnimRecord;
  30.         AnimRecord = record
  31.                 numEntries: integer;
  32.                 entries: array[0..99] of record
  33.                         objectCode: integer;
  34.                         firstBrgrID: integer;
  35.                         frameMenu: integer;
  36.                     end;
  37.             end;
  38.  
  39.         TEnemyImagePalette = object(TImagePalette)
  40.                 procedure IEnemyImagePalette;
  41.                 procedure DrawImage (itemNo: integer; r: Rect);
  42.                 override;
  43.                 function ItemSelectable (item: integer): boolean;
  44.                 override;
  45.             end;
  46.  
  47.         TEnemyEditDialog = object(TArtEditDialog)
  48.                 fCurrentFrame: integer;
  49.                 procedure IEnemyEditDialog (itsMapList: TMapListDoc);
  50.                 procedure UninstallArt;
  51.                 override;
  52.                 procedure InstallArt;
  53.                 override;
  54.                 procedure TEnemyEditDialog.UninstallFrame;
  55.                 procedure TEnemyEditDialog.InstallFrame;
  56.                 function TEnemyEditDialog.CurrentObjectCode: integer;
  57.                 function TEnemyEditDialog.CurrentFrameBrgrID: integer;
  58.                 procedure TEnemyEditDialog.GoToFrame (i: integer);
  59.                 procedure TEnemyEditDialog.SetUpFrameButtons;
  60.                 procedure TEnemyEditDialog.ItemHit (var e: EventInfo; itemNo: integer);
  61.                 override;
  62.                 function ArtImageType: CustomImageType;
  63.                 override;
  64.                 function ArtImageCode: integer;
  65.                 override;
  66.                 procedure ChangeImage (gworld: GWorldPtr; isThumbnail: boolean);
  67.                 override;
  68.             end;
  69.  
  70.     var
  71.  
  72.         gAnims: AnimHandle;
  73.  
  74.     function ObjectCode (itemNo: integer): integer;
  75.     begin
  76.         ObjectCode := gAnims^^.entries[itemNo].objectCode;
  77.     end;
  78.  
  79.     procedure TEnemyImagePalette.IEnemyImagePalette;
  80.     begin
  81.         IImagePalette(16, gAnims^^.numEntries);
  82.         fDialog := nil;
  83.     end;
  84.  
  85.     procedure TEnemyImagePalette.DrawImage (itemNo: integer; r: Rect);
  86.         var
  87.             n: integer;
  88.     begin
  89.         fDialog.fMapList.PlotObject(ObjectCode(itemNo), 0, r);
  90.     end;
  91.  
  92.     function TEnemyImagePalette.ItemSelectable (item: integer): boolean;
  93.     begin
  94.         ItemSelectable := fDialog.fMapList.ObjectAvailable(ObjectCode(item));
  95.     end;
  96.  
  97.     procedure TEnemyEditDialog.IEnemyEditDialog (itsMapList: TMapListDoc);
  98.         var
  99.             palette: TEnemyImagePalette;
  100.     begin
  101.         new(palette);
  102.         palette.IEnemyImagePalette;
  103.         IArtEditDialog(enemyEditDlogID, palette, itsMapList, true);
  104.         palette.fDialog := self;
  105.         fCurrentFrame := 0;
  106.         SetDismissItems([ok]);
  107.     end;
  108.  
  109.     procedure TEnemyEditDialog.UninstallArt;
  110.     begin
  111.         UninstallFrame;
  112.     end;
  113.  
  114.     procedure TEnemyEditDialog.InstallArt;
  115.         type
  116.             MenuHandleHandle = ^MenuHandlePtr;
  117.             MenuHandlePtr = ^MenuHandle;
  118.         var
  119.             iHandle, newCtl: ControlHandle;
  120.             iType: integer;
  121.             iRect: Rect;
  122.     begin
  123.         GetItem(frameMenuItem, iType, Handle(iHandle), iRect);
  124.         iRect := iHandle^^.contrlRect;
  125.         newCtl := NewCtrl(nil, iRect, iHandle^^.contrlTitle, false, 1, gAnims^^.entries[fCurrentArt].frameMenu, 62, 1008);
  126.         DisposeCtrl(iHandle);
  127.         SetItem(frameMenuItem, iType, Handle(newCtl), iRect);
  128.         ShowControl(newCtl);
  129.         ValidateRect(iRect);
  130.         fCurrentFrame := 0;
  131.         SetUpFrameButtons;
  132.         InstallFrame;
  133.     end;
  134.  
  135.     procedure TEnemyEditDialog.UninstallFrame;
  136.     begin
  137.         if (fCurrentArt >= 0) & (fArtView.fChanged) then begin
  138.                 fMapList.InstallObjectArt(CurrentFrameBrgrID, fArtView.ExtractObject);
  139.                 fArtView.fChanged := false;
  140.             end;
  141.     end;
  142.  
  143.     procedure TEnemyEditDialog.InstallFrame;
  144.     begin
  145.         if fCurrentArt >= 0 then
  146.             fArtView.InstallObject(fMapList.GetObjectArt(CurrentFrameBrgrID));
  147.     end;
  148.  
  149.     function TEnemyEditDialog.CurrentObjectCode: integer;
  150.     begin
  151.         CurrentObjectCode := ObjectCode(fCurrentArt);
  152.     end;
  153.  
  154.     function TEnemyEditDialog.CurrentFrameBrgrID: integer;
  155.     begin
  156.         CurrentFrameBrgrID := gAnims^^.entries[fCurrentArt].firstBrgrID + fCurrentFrame;
  157.     end;
  158.  
  159.     procedure TEnemyEditDialog.GoToFrame (i: integer);
  160.         var
  161.             lo, hi: integer;
  162.     begin
  163.         if i - 1 <> fCurrentFrame then begin
  164.                 GetItemMinMax(frameMenuItem, lo, hi);
  165.                 if (lo <= i) & (i <= hi) then begin
  166.                         UninstallFrame;
  167.                         fCurrentFrame := i - 1;
  168.                         SetItemValue(frameMenuItem, i);
  169.                         SetUpFrameButtons;
  170.                         InstallFrame;
  171.                     end;
  172.             end;
  173.     end;
  174.  
  175.     procedure TEnemyEditDialog.SetUpFrameButtons;
  176.         var
  177.             i, lo, hi: integer;
  178.     begin
  179.         GetItemMinMax(frameMenuItem, lo, hi);
  180.         i := GetItemValue(frameMenuItem);
  181.         EnableItem(prevFrameItem, i > lo);
  182.         EnableItem(nextFrameItem, i < hi);
  183.     end;
  184.  
  185.     procedure TEnemyEditDialog.ItemHit (var e: EventInfo; itemNo: integer);
  186.     begin
  187.         inherited ItemHit(e, itemNo);
  188.         case itemNo of
  189.             frameMenuItem: 
  190.                 GoToFrame(GetItemValue(frameMenuItem));
  191.             prevFrameItem: 
  192.                 GoToFrame(GetItemValue(frameMenuItem) - 1);
  193.             nextFrameItem: 
  194.                 GoToFrame(GetItemValue(frameMenuItem) + 1);
  195.             otherwise
  196.                 ;
  197.         end;
  198.     end;
  199.  
  200.     function TEnemyEditDialog.ArtImageType: CustomImageType;
  201.     begin
  202.         ArtImageType := objectImage;
  203.     end;
  204.  
  205.     function TEnemyEditDialog.ArtImageCode: integer;
  206.     begin
  207.         ArtImageCode := CurrentObjectCode;
  208.     end;
  209.  
  210.     procedure TEnemyEditDialog.ChangeImage (gworld: GWorldPtr; isThumbnail: boolean);
  211.     begin
  212.         if isThumbNail or (fCurrentFrame = 0) then
  213.             ChangeObjectImage(ArtImageCode, gworld);
  214.     end;
  215.  
  216.     procedure EditEnemies (mapList: TMapListDoc);
  217.         var
  218.             dlog: TEnemyEditDialog;
  219.  
  220.         procedure CheckWindow (win: TWindow);
  221.         begin
  222.             if member(win, TEnemyEditDialog) then begin
  223.                     win.Select;
  224.                     exit(EditEnemies);
  225.                 end;
  226.         end;
  227.  
  228.     begin
  229.         mapList.EachWindowDo(CheckWindow);
  230.         new(dlog);
  231.         dlog.IEnemyEditDialog(mapList);
  232.         dlog.Show;
  233.     end;
  234.  
  235.     procedure IUEditEnemies;
  236.     begin
  237.         gAnims := AnimHandle(GetResource('ANIM', animRsrcID));
  238.     end;
  239.  
  240. end.